package com.yanqu.road.server.manger.activity.peakseacraft;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.peakseacraft.config.PeakSeacraftActivityConfig;
import com.yanqu.road.entity.activity.peakseacraft.config.PeakSeacraftDonateConfig;
import com.yanqu.road.entity.activity.peakseacraft.config.PeakSeacraftLastGuessConfig;
import com.yanqu.road.entity.activity.peakseacraft.config.PeakSeacraftRoundScoreConfig;
import com.yanqu.road.entity.activity.seacraft.config.*;
import com.yanqu.road.entity.config.patrons.PatronsInfo;
import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.entity.player.UserPatronsSkill;
import com.yanqu.road.entity.union.UnionBaseInfo;
import com.yanqu.road.entity.union.UnionInfo;
import com.yanqu.road.entity.union.UnionMember;
import com.yanqu.road.entity.union.activitygroup.UnionActivityGroup;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.logic.bussiness.activity.PeakSeacraftBusiness;
import com.yanqu.road.logic.bussiness.activity.SeacraftSouthSeaBusiness;
import com.yanqu.road.logic.bussiness.player.UserPatronsBussiness;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.logic.helper.UnionActivityGroupHelper;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.logic.pb.UnionBasePb;
import com.yanqu.road.logic.rank.UnionRankMsgModel;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PeakSeacraftProto;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.peakseacraft.PeakSeacraftModule;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.CommonActivityRankMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.config.PatronsMgr;
import com.yanqu.road.server.manger.config.SkillMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.ConfigHelper;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.mina.util.ConcurrentHashSet;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description 海上争霸 之 南海丝路
 */
public class PeakSeacraftMgr extends TempMgr {

    private static ActivityInfo activityInfo;

    /**
     * 配置
     */
    private static PeakSeacraftActivityConfig config;


    public static RandomHelper randomHelper = new RandomHelper();

    /**
     * key:unionGroup
     */
    private static Map<Integer, PeakSeacraftGroup> peakSeacraftGroupMap = new ConcurrentHashMap<>();

    public static int curRound = 0;

    @Override
    public boolean init() throws Exception {
        return true;
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

    public static void reloadActivityData() {
        getLogger().info("reload PeakSeacraft Activity start");
        List<ActivityInfo> openActivityInfoList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.PeakSeacraftActivity.getValue());
        if (openActivityInfoList.isEmpty()) {
            getLogger().info("no PeakSeacraft Activity in show time");
            activityInfo = null;
            config = null;
            peakSeacraftGroupMap.clear();
        } else {
            ActivityInfo tempActivityInfo = openActivityInfoList.get(0);
            List<Integer> activityIdList = new ArrayList<>();
            activityIdList.add(tempActivityInfo.getActivityId());
            Map<String, ActivityConfig> activityConfigMap = ActivityBussiness.getActivityConfigMap(activityIdList).get(tempActivityInfo.getActivityId());
            PeakSeacraftActivityConfig configTemp = new PeakSeacraftActivityConfig(tempActivityInfo);
            configTemp.setShipList(SeacraftSouthSeaBusiness.getSeacraftSouthSeaShipConfigList(tempActivityInfo.getActivityId()));
            configTemp.setFloorList(SeacraftSouthSeaBusiness.getSeacraftSouthSeaFloorConfigList(tempActivityInfo.getActivityId()));
            configTemp.setBattleList(SeacraftSouthSeaBusiness.getSeacraftSouthSeaBattleConfigList(tempActivityInfo.getActivityId()));
            configTemp.setSilverDonateList(PeakSeacraftBusiness.getPeakSeacraftDonateConfigList(tempActivityInfo.getActivityId()));
            configTemp.setRoundScoreMap(PeakSeacraftBusiness.getPeakSeacraftRoundScoreConfigList(tempActivityInfo.getActivityId()));
            configTemp.setGuessList(PeakSeacraftBusiness.getPeakSeacraftLastGuessConfigList(tempActivityInfo.getActivityId()));
            configTemp.parseConfig(activityConfigMap);

            activityInfo = tempActivityInfo;
            config = configTemp;
            curRound = config.getCurRound();
        }

        if (activityInfo != null) {
            for (GamePlayer gamePlayer : GamePlayerMgr.getAllOnlinePlayer()) {
                PeakSeacraftModule peakSeacraftModule = gamePlayer.getModule(PeakSeacraftModule.class);
                peakSeacraftModule.sendConfigToClient();
                peakSeacraftModule.synUserData();
            }
            List<Integer> removeGroupList = new ArrayList<>();
            for (PeakSeacraftGroup group : peakSeacraftGroupMap.values()) {
                if (group.getActivityId() != activityInfo.getActivityId()) {
                    removeGroupList.add(group.getUnionGroup());
                }
            }
            for (Integer group : removeGroupList) {
                peakSeacraftGroupMap.remove(group);
            }
        }

        getLogger().info("reload Seacraft SouthSea Activity finish");
    }

    public static PeakSeacraftGroup getPeakSeacraftGroup(int unionGroup) {
        if (unionGroup == UnionActivityGroupHelper.NO_GROUP_ID) {
            return null;
        }
        if (activityInfo == null) {
            return null;
        }
        PeakSeacraftGroup peakSeacraftGroup = peakSeacraftGroupMap.get(unionGroup);
        if (peakSeacraftGroup == null) {
            synchronized (peakSeacraftGroupMap) {
                peakSeacraftGroup = peakSeacraftGroupMap.get(unionGroup);
                if (peakSeacraftGroup == null) {
                    peakSeacraftGroup = new PeakSeacraftGroup(activityInfo.getActivityId(), unionGroup);
                    peakSeacraftGroupMap.put(unionGroup, peakSeacraftGroup);
                }
            }
        }
        return peakSeacraftGroup;
    }

    public static ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public static PeakSeacraftActivityConfig getConfig() {
        return config;
    }

    /**
     * 是否玩家可以进入活动
     */
    public static int canEntryActivity(GamePlayer player, int activityId) {
        if (!ActivityMgr.activityInShowTime(getActivityInfo())) {
            return GameErrorCode.E_SEACRAFT_SOUTH_SEA_ACTIVITY_NO_OPEN;
        }
        if (!SystemOpenMgr.systemOpen(player, eSystemId.PeakSeacraft.getValue())) {
            return GameErrorCode.E_SEACRAFT_SOUTH_SEA_ACTIVITY_NO_UNLOCK;
        }
        if (getActivityInfo() == null || getActivityInfo().getActivityId() != activityId || null == config) {
            return GameErrorCode.E_SEACRAFT_SOUTH_SEA_ACTIVITY_NO_OPEN;
        }
        return 0;
    }

    public static int canEntryActivity(GamePlayer player) {
        if (!ActivityMgr.activityInShowTime(getActivityInfo())) {
            return GameErrorCode.E_SEACRAFT_SOUTH_SEA_ACTIVITY_NO_OPEN;
        }
        if (!SystemOpenMgr.systemOpen(player, eSystemId.PeakSeacraft.getValue())) {
            return GameErrorCode.E_SEACRAFT_SOUTH_SEA_ACTIVITY_NO_UNLOCK;
        }
        if (getActivityInfo() == null) {
            return GameErrorCode.E_SEACRAFT_SOUTH_SEA_ACTIVITY_NO_OPEN;
        }
        return 0;
    }

    public static PeakSeacraftProto.SyncPeakSeacraftConfig.Builder builderPeakSeacraftConfig(String language) {
        PeakSeacraftProto.SyncPeakSeacraftConfig.Builder builder = PeakSeacraftProto.SyncPeakSeacraftConfig.newBuilder();
        for (SeacraftSouthSeaShipConfig item : config.getShipList()) {
            PeakSeacraftProto.PeakSeacraftShipConfig.Builder shipConfig = PeakSeacraftProto.PeakSeacraftShipConfig.newBuilder();
            shipConfig.setLevel(item.getLevel());
            shipConfig.setExp(item.getExp());
            shipConfig.setSpeed(item.getSpeed());
            shipConfig.setHealth(item.getHealth());
            shipConfig.setBonus(item.getBonus());
            shipConfig.setShip(item.getShip());
            builder.addShipConfigList(shipConfig);
        }
        for (PeakSeacraftLastGuessConfig item : config.getGuessList()) {
            PeakSeacraftProto.PeakSeacraftGuessConfig.Builder guessConfig = PeakSeacraftProto.PeakSeacraftGuessConfig.newBuilder();
            guessConfig.setId(item.getId());
            guessConfig.setCount(item.getCount());
            guessConfig.setDesc(ServerLanguageMgr.getContent(item.getDesc(), language));
            guessConfig.setAward(item.getAward());
            guessConfig.setShow(item.getShow());
            builder.addGuessConfigList(guessConfig);
        }

        for (SeacraftSouthSeaFloorConfig item : config.getFloorList()) {
            PeakSeacraftProto.PeakSeacraftFloorConfig.Builder floorConfig = PeakSeacraftProto.PeakSeacraftFloorConfig.newBuilder();
            floorConfig.setFloor(item.getFloor());
            floorConfig.setSpecialReward(item.getSpecialReward());
            floorConfig.setRewards(item.getRewards());
            floorConfig.setConsume(item.getConsume());
            builder.addFloorConfigList(floorConfig);
        }

        for (SeacraftSouthSeaBattleConfig item : config.getBattleList()) {
            PeakSeacraftProto.PeakSeacraftBattleConfig.Builder battleConfig = PeakSeacraftProto.PeakSeacraftBattleConfig.newBuilder();
            battleConfig.setId(item.getId());
            battleConfig.setRound(item.getRound());
            battleConfig.setType(item.getType());
            battleConfig.setVictoryTime(item.getVictoryTime());
            battleConfig.setRank(item.getRank());
            battleConfig.setAward(item.getAward());
            builder.addBattleConfigList(battleConfig);
        }

        for (PeakSeacraftDonateConfig item : config.getSilverDonateList()) {
            PeakSeacraftProto.PeakSeacraftSilverDonateConfig.Builder configMsg = PeakSeacraftProto.PeakSeacraftSilverDonateConfig.newBuilder();
            configMsg.setCount(item.getId());
            configMsg.setCostValue(item.getCost());
            configMsg.setAddPro(item.getAddPro());
            builder.addSilverDonateConfigList(configMsg);
        }

        config.getRoundScoreMap().forEach((key, peakSeacraftRoundScoreConfigs) -> {
            for (PeakSeacraftRoundScoreConfig roundScoreConfig : peakSeacraftRoundScoreConfigs) {
                PeakSeacraftProto.PeakSeacraftRoundScoreConfig.Builder configMsg = PeakSeacraftProto.PeakSeacraftRoundScoreConfig.newBuilder();
                configMsg.setArea(roundScoreConfig.getArea());
                configMsg.setRound(roundScoreConfig.getRound());
                configMsg.setRank(roundScoreConfig.getRank());
                configMsg.setScore(roundScoreConfig.getScore());
                builder.addRoundSocreConfigList(configMsg);
            }
        });

        return builder;
    }

    /**
     * 是否晋级
     *
     * @return
     */
    public static boolean isPromotion(String unionId) {
        if (StringUtils.isNullOrEmpty(unionId)) {
            return false;
        }
        if (null == config) {
            return false;
        }

        int unionGroup = GameUnionActivityGroupMgr.getGroupId(activityInfo.getActivityId(), unionId);
        PeakSeacraftGroup peakSeacraftGroup = getPeakSeacraftGroup(unionGroup);
        if (peakSeacraftGroup == null) {
            return false;
        }
        return peakSeacraftGroup.isPromotion(unionId);
    }

    /**
     * 获取各个 类型门客 门客集合 并按 赚钱 高到低 排序
     *
     * @param userId
     * @return
     */
    public static Map<Integer, List<UserPatrons>> getPatronsMap(long userId) {
        GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
        Map<Integer, UserPatrons> patronsMap = null;
        if (player != null) {
            PatronsModule patronsModule = player.getModule(PatronsModule.class);
            patronsMap = patronsModule.getUserPatronsMap();
        } else {
            patronsMap = UserPatronsBussiness.getUserPatronsAndSkillMap(userId);
        }
        Map<Integer, List<UserPatrons>> patronMap = new HashMap<>();
        for (UserPatrons item : patronsMap.values()) {
            PatronsInfo patronsInfo = PatronsMgr.getPatronsInfoMap().get(item.getPatronsId());
            if (patronsInfo != null) {
                List<UserPatrons> list = patronMap.get(patronsInfo.getOccupation());
                if (list == null) {
                    list = new ArrayList<>();
                    patronMap.put(patronsInfo.getOccupation(), list);
                }
                list.add(item);
            }
        }
        // 排序
        patronMap.values().forEach(e -> {
            e.sort((t1, t2) -> {
                // 按战斗力排序
                return PeakSeacraftActivityConfig.comparator(t1.getPatronsId(), t1.getAbility().longValue(), getAddPlus(t1), t2.getPatronsId(), t2.getAbility().longValue(), getAddPlus(t2));
            });
        });
        return patronMap;
    }

    public static void exit(long userId) {
        if (activityInfo == null) {
            return;
        }
        int unionGroup = GameUnionActivityGroupMgr.getGroupId(activityInfo.getActivityId(), userId);
        PeakSeacraftGroup peakSeacraftGroup = getPeakSeacraftGroup(unionGroup);
        if (peakSeacraftGroup == null) {
            return;
        }
        peakSeacraftGroup.exit(userId);
    }

    public static void enter(long userId, int area, int group) {
        if (activityInfo == null) {
            return;
        }
        int unionGroup = GameUnionActivityGroupMgr.getGroupId(activityInfo.getActivityId(), userId);
        PeakSeacraftGroup peakSeacraftGroup = getPeakSeacraftGroup(unionGroup);
        if (peakSeacraftGroup == null) {
            return;
        }
        peakSeacraftGroup.enter(userId, area, group);
    }

    public static void offLine(GamePlayer player) {
        if (!ActivityMgr.activityInShowTime(getActivityInfo())) {
            return;
        }
        if (!SystemOpenMgr.systemOpen(player, eSystemId.PeakSeacraft.getValue())) {
            return;
        }
        exit(player.getUserId());
    }

    /**
     * @param patrons 要计算的当前门客
     * @return
     */
    public static PeakSeacraftProto.PeakSeacraftPatronsEntity.Builder builderPeakSeacraftPatronsEntity(UserPatrons patrons) {
        int addPlus = 0;
        // 计算该门客的自己战斗加成
        addPlus = getAddPlus(patrons);

        PeakSeacraftProto.PeakSeacraftPatronsEntity.Builder builder = PeakSeacraftProto.PeakSeacraftPatronsEntity.newBuilder();
        builder.setPatronsId(patrons.getPatronsId());
        builder.setLevel(patrons.getLevel());
        builder.setStageLv(patrons.getStageLv());
        builder.setSkinId(patrons.getSkinId());
        builder.setEarn(patrons.getAbility().longValue());
        builder.setAddPlus(addPlus);
        builder.setPromotionId(patrons.getShowPromotionId());
        return builder;
    }

    public static int getAddPlus(UserPatrons patrons) {
        int addPlus = 0;
        if (patrons != null) {
            for (UserPatronsSkill userPatronsSkill : patrons.getSkillList()) {
                SkillInfo skillInfo = SkillMgr.getSkillInfo(userPatronsSkill.getSkillId());
                if (skillInfo == null){
                    continue;
                }
                if (skillInfo.getType() == eSkillType.BattleEffect.getValue()) {
                    addPlus += SkillMgr.getSkillAddition(skillInfo, userPatronsSkill.getSkillLv());
                }
            }
        }
        return addPlus;
    }

    /**
     * 向跨服索要晋级联盟的数据
     */
    public static synchronized void getPromotionUnionList() {
        if (!hasActivity()) {
            return;
        }
        Map<Integer, UnionActivityGroup> groupMap = GameUnionActivityGroupMgr.getGroupMap(activityInfo.getActivityId());
        if (groupMap == null) {
            return;
        }
        for (UnionActivityGroup unionActivityGroup : groupMap.values()) {
            PeakSeacraftGroup peakSeacraftGroup = getPeakSeacraftGroup(unionActivityGroup.getGroupId());
            if (peakSeacraftGroup == null) {
                continue;
            }
            peakSeacraftGroup.getPromotionUnionList();
        }
    }

    public static void synPatronsAbility(GamePlayer player, List<UserPatrons> patronsList) {
        if (patronsList == null) {
            return;
        }
        if (!hasActivity()) {
            return;
        }
        // 判断该玩家的联盟是否晋级
        int curRound = config.getCurRound();
        if (curRound > config.getMaxRoundCount()) {
            // 最后一轮了 判断是否结束了
            return;
        }

        if (canEntryActivity(player, activityInfo.getActivityId()) != 0) {
            return;
        }
        int unionGroup = GameUnionActivityGroupMgr.getGroupId(activityInfo.getActivityId(), player.getUserId());

        PeakSeacraftGroup peakSeacraftGroup = getPeakSeacraftGroup(unionGroup);
        if (peakSeacraftGroup != null) {
            peakSeacraftGroup.addSyncPatronsAbility(player, patronsList);
        }
    }


    /**
     * 同步门客数据
     */
    public static void uploadObjectInfo() {
        for (PeakSeacraftGroup peakSeacraftGroup : peakSeacraftGroupMap.values()) {
            peakSeacraftGroup.uploadObjectInfo();
        }
    }

    /**
     * 当前阶段是否能进出商会 或解散商会
     *
     * @param unionId
     * @return
     */
    public static boolean canInAndOutUnion(String unionId) {
        if (!hasActivity()) {
            return true;
        }
        int curRound = config.getCurRound();
        if (curRound == 0 || curRound > config.getMaxRoundCount()) {
            // 不在 海盗之乱结束- 南海丝路结束 区间
            return true;
        }
        int unionGroup = GameUnionActivityGroupMgr.getGroupId(activityInfo.getActivityId(), unionId);
        PeakSeacraftGroup peakSeacraftGroup = getPeakSeacraftGroup(unionGroup);
        if (peakSeacraftGroup == null) {
            return true;
        }
        return peakSeacraftGroup.canInAndOutUnion(unionId);
    }

    /**
     * 获取本轮晋级的联盟集合
     *
     * @return
     */
    public static List<String> getCurRoundPromotionUnionList() {
        if (!hasActivity()) {
            return null;
        }
        int curRound = config.getCurRound();
        if (curRound == 0 || curRound > config.getMaxRoundCount()) {
            // 不在 海盗之乱结束- 南海丝路结束 区间
            return null;
        }

        List<String> allUnionIds = new ArrayList<>();
        for (PeakSeacraftGroup peakSeacraftGroup : peakSeacraftGroupMap.values()) {
            allUnionIds.addAll(peakSeacraftGroup.getJoinUnionList());
        }

        return allUnionIds;
    }

    /**
     * 同步联盟信息
     *
     * @param type
     * @param unionId
     * @param userId
     * @param position
     */
    public static void synUnionInfo(int type, String unionId, long userId, int position) {
        if (!hasActivity()) {
            return;
        }

        int unionGroup = GameUnionActivityGroupMgr.getGroupId(activityInfo.getActivityId(), unionId);
        PeakSeacraftGroup peakSeacraftGroup = getPeakSeacraftGroup(unionGroup);
        if (peakSeacraftGroup == null) {
            return;
        }
        peakSeacraftGroup.synUnionInfo(type, unionId, userId, position);
    }


    public static boolean hasActivity() {
        if (activityInfo == null || config == null) {
            return false;
        }
        return true;
    }

    public static boolean isInRegistration() {
        if (0 == config.getCurRound()) {
            return true;
        }
        return false;
    }

    /**
     * 检查有没有缓存到报名期排行
     */
    public static void checkRegistrationList() {
        if (!hasActivity()) {
            return;
        }

        UnionRankMsgModel model = CommonActivityRankMgr.getUnionRankMsgModel(activityInfo.getActivityId());
        if (null != model) {
            model.setRankNum(config.getRegistrationNum() + 20);
            model.setActivityEndTime(activityInfo.getEndShowTime());
            if (model.getRankListMsg().getRankListCount() == 0 && !model.isInReq()) {
                CrossUnionProto.CrossUnionGetMaxAbilityUnionRankListReq.Builder crossReqMsg = CrossUnionProto.CrossUnionGetMaxAbilityUnionRankListReq.newBuilder();
                crossReqMsg.setActivityId(activityInfo.getActivityId());
                crossReqMsg.addAllServerIds(activityInfo.getServerIdList());
                crossReqMsg.setRankNum(model.getRankNum());
                crossReqMsg.setActivityEndTime(activityInfo.getEndShowTime());
                GamePlayerMgr.sendPacket(0, YanQuMessageUtils.buildMessage(Protocol.C_UNION_GET_MAX_ABILITY_UNION_RANK_LIST, crossReqMsg));
            }
        }
    }

    /**
     * 对进入系统的玩家广播
     */
    public static void Broadcast(PeakSeacraftProto.PeakSeacraftBroadcastCrossToGameMsg msg) {
        PeakSeacraftGroup peakSeacraftGroup = getPeakSeacraftGroup(msg.getUnionGroup());
        if (peakSeacraftGroup == null) {
            return;
        }
        peakSeacraftGroup.Broadcast(msg);
    }

    /**
     * 领奖期获得指定道具要回收,船桨,火药,扳手(废弃),捐献道具
     */
    public static boolean isNeedRecycleItem(int goodsId) {
        if (null == config) {
            return false;
        }
        if (config.getCurRound() <= config.getMaxRoundCount()) {
            return false;
        }
        if (goodsId == config.getSEACRAFT_CRAFT_FIRE_ITEM_ID()) {
            return true;
        } else if (config.hasPaddleId(goodsId)) {
            return true;
        } else if (goodsId == config.getSEACRAFT_CRAFT_WRENCH_ITEM_ID()) {
            return true;
        } else if (goodsId == config.getSEACRAFT_CRAFT_DONATE_ITEMS()) {
            return true;
        }

        return false;
    }

    /**
     * 回合更新，让在线玩家回收一下道具
     */
    public static void roundChangeTask() {
        if (null == config) {
            return;
        }
        if (curRound == config.getCurRound()) {
            return;
        }
        curRound = config.getCurRound();
        for (GamePlayer gamePlayer : GamePlayerMgr.getAllOnlinePlayer()) {
            PeakSeacraftModule peakSeacraftModule = gamePlayer.getModule(PeakSeacraftModule.class);
            peakSeacraftModule.roundReset();
        }
    }

    public static boolean isOpenTime() {
        if (null == config) {
            return false;
        }
        return config.isOpenTime();
    }

    public synchronized static void lockJoinUnionFromCross(PeakSeacraftProto.PeakSeacraftSynPromotionUnionCrossToGameMsg crossToGameMsg) {
        int unionGroup = crossToGameMsg.getUnionGroup();
        PeakSeacraftGroup peakSeacraftGroup = getPeakSeacraftGroup(unionGroup);
        if (peakSeacraftGroup == null) {
            getLogger().error("巅峰海战活动{},找不到商会分组{}", crossToGameMsg.getActivityId(), crossToGameMsg.getUnionGroup());
            return;
        }
        peakSeacraftGroup.lockJoinUnionFromCross(crossToGameMsg);
    }

}
